(function ($) {
    var _this = this,
        c = $("#Consignee"),
        d = $("#Telephone"),
        e = $("#province"),
        f = $("#city"),
        g = $("#area"),
        h = $("#Street"),
        i = $("#Zipcode"),
        j = $("#Tag"),
        k = /^[1-9]+\d*$/,
        l = /^\d{6}$/,
        m = /^1[34578][0-9]{9}$/,
        n = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/,
        o = /^\d+$/,
        p = /^[0-9a-zA-Z]+$/,
        q = /^[a-zA-Z\u4e00-\u9fa5]+$/,
        r = {},
        s = $("#addrState").val(),
        u = c.attr("placeholder"),
        v = {};

    c.change(function () {
        var t = $.trim(c.val())
        if(t === u && (t = ""), !(_this.strLen(t) >= 4)){
            return _this.setMsg(c,"收货人姓名 太短 (最小值为 2 个中文字)"), v.c = !1;
        }
        if (!q.test(t)) {
            return _this.setMsg(c, "收货人姓名不正确（只能是英文、汉字）"), v.c = !1
        };
        _this.setMsg(c, ""), r.consignee = t, v.c = !0;
    });

    d.change(function () {
        var t = $
        if(!m.test(d.val())){
            return _this.setMsg(d,"请填写正确的手机号码"),v.d = !1
        }
        _this.setMsg(d, ""), r.phone = t, v.d = !0;
    })

    e,f,g.change(function () {
        if(e.val() != -1 && f.val() != -1 && g.val() != -1)
    })

    dayingdizhi = function() {
        validation(true)
        var province = $("#province").val();
        var city = $("#city").val();
        var area = $("#area").val();
        console.log(getprovince(province, city, area));
    }

    showmodel = function(data) {
        $("#myModal").css("display", "block");
    }

    gbtc = function() {
        if (confirm("退出系统将不会保存你输入的地址，确认退出吗？")) {
            $("#myModal").css("display", "none");
        }
    }

    getprovince = function (province, city, area) {
        var province_addr = provinceList[province].name;
        var city_addr = provinceList[province].cityList[city].name;
        var area_addr = provinceList[province].cityList[city].areaList[area];
        var address = province_addr + city_addr + area_addr;
        return address;
    }

    validation = function (a) {
        var _this = this,
            c = $("#Consignee"),
            d = $("#Telephone"),
            e = $("#province"),
            f = $("#city"),
            g = $("#area"),
            h = $("#Street"),
            i = $("#Zipcode"),
            j = $("#Tag"),
            k = /^[1-9]+\d*$/,
            l = /^\d{6}$/,
            m = /^1[34578][0-9]{9}$/,
            n = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/,
            o = /^\d+$/,
            p = /^[0-9a-zA-Z]+$/,
            q = /^[a-zA-Z\u4e00-\u9fa5]+$/,
            r = {},
            s = $("#addrState").val(),
            t = $.trim(c.val()),
            u = c.attr("placeholder"),
            v = !1;
        if (t === u && (t = ""), !(_this.strLen(t) >= 4)) return c.focus(), _this.setMsg(c, "收货人姓名 太短 (最小值为 2 个中文字)"), !1;
        if (!q.test(t)) return c.focus(), _this.setMsg(c, "收货人姓名不正确（只能是英文、汉字）"), !1;
        _this.setMsg(c, ""), r.consignee = t, v = !0;
        var w = $.trim(i.val()),
            x = !1;
        if (a && w && w !== i.attr("placeholder") ? a = !1 : !a && w && w === i.attr("placeholder") ? i.attr("placeholder",
                "") : a || w || i.attr("placeholder", "11位手机号"), !a && w !== i.attr("placeholder") && !m.test(w)) return i.focus(),
            _this.setMsg(i, "请填写11位手机号"), !1;
        _this.setMsg(i, ""), r.tel = w, r.telPlaceholder = i.attr("placeholder"), x = !0;
        var y = d.val(),
            z = e.val(),
            A = f.val(),
            B = !1;
        if (!(k.test(y) && k.test(z) && k.test(A))) return _this.setMsg(d, "收货地址不正确"), !1;
        _this.setMsg(d, ""), r.province = y, r.city = z, r.county = A, r.provinceName = _this.newProvince, r.cityName = _this.newCity,
            r.countyName = _this.newCounty, B = !0;
        var C = $.trim(g.val()).replace(/</g, "").replace(/>/g, "").replace(/\//g, "").replace(/\\/g, ""),
            D = g.attr("placeholder"),
            E = !1;
        if (C === D && (C = ""), !(C.length >= 5 && C.length <= 32)) return g.focus(), _this.setMsg(g,
            "详细地址长度不对，最小为 5 个字，最大32个字"), !1;
        if (n.test(C) || o.test(C) || p.test(C)) return g.focus(), _this.setMsg(g, "详细地址不正确"), !1;
        _this.setMsg(g, ""), r.street = C, E = !0;
        var F = $.trim(h.val()),
            G = !1;
        if (!l.test(F)) return h.focus(), _this.setMsg(h, "邮编是6位数字"), !1;
        _this.setMsg(h, ""), r.zipcode = F, G = !0;
        var H = $.trim(j.val()),
            I = j.attr("placeholder"),
            J = !1;
        if (H === I && (H = ""), H.length > 5) return j.focus(), _this.setMsg(j, "地址标签最长5个字"), !1;
        if (r.tag = H, J = !0, v && B && E && G && x && J)
            if ("1" === s) {
                var K = $("#checkoutAddrList").find(".selected").attr("data-isnew");
                "true" === K && $("#checkoutAddrList").find(".selected").remove(), r.tel || (r.tel = r.telPlaceholder), _this.createAddr(
                    r), _this.Close(), _this.resetData()
            } else _this.saveAddr(r)
    }

    setMsg =  function (a, b) {
        a && b ? a.siblings(".tipMsg").html(b).show() : a.siblings(".tipMsg").html("").hide()
    }
    strLen = function (a) {
        return a.replace(/[^\x00-\xff]/g, "**").length
    }
}(jQuery))